package cn.kgc.springmvc01.controller;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * @author: mosin
 * @version: v1.0  2022/12/8
 * springmvc框架中习惯将控制层 命名为xxxController
 *
 * localhost:8080/user/delete?id = 20
 * @RequestMapping 的使用  请求映射  标记控制层能处理的请求路径
 * path:  String[]     可以设置多个请求路径的匹配
 * method:  RequestMethod[]  设置请求的方式  method = RequestMethod.POST
 *
 * 传统路径设计风格
 * localhost:8080/user/delete?id=10
 * localhost:8080/user/add?id=10&username=tom
 * localhost:8080/user/select?id=10
 * localhost:8080/user/update?id=10&username=tom
 *
 * restful设计风格  ->  根据不同的请求方式 来区分操作类型  @DeleteMapping   @PostMapping  @PutMapping @GetMapping
 * localhost:8080/user    CRUD
 * localhost:8080/user   get   ->查询
 * localhost:8080/user   post   ->添加
 * localhost:8080/user   delete   ->删除
 * localhost:8080/user   put   ->修改       swagger  ->接口文档
 */
@Controller
@RequestMapping("user")
public class UserController {
    
    @RequestMapping(path = {"delete2","delete1"},method = {RequestMethod.GET,RequestMethod.POST})
    public String deleteById(int id){
        System.out.println("删除用户请求被接收"+id);
        return "index";  //  转发
    }

    @RequestMapping("add")
    public String add(){
        System.out.println("添加用户请求被接收");
        return "index";
    }

}
